 
<?php 
	include_once("header.php");
?>

<script type="text/javascript"  src="/include/ajaxfileupload.js"></script>

<link rel="stylesheet" href="/include/coachdash.css">

<div id="regbox">
     <div id="regform" >
		      <!-- step 1 -->
		       <div id="step1" style=" position:relative; ">

 				      <div class="formgroup" style="height:100px">
					       <h3>上传头像</h3>
					               <div class="inputcontent">
					               <img src="<?=$coach->thumb?>" id="userthumb"> 
		                      <input id="userthumbfile" name="file" type="file" accept="image/*;capture=camera" onchange="upload('userthumbfile')" style="opacity:0; height:1px; width:1px; -webkit-appearance: none;  -moz-appearance: none; appearance: none; overflow: hidden;  " >
					               </div>
					    </div>

 			         <div class="formgroup">
			               <h3><span class="mustspan">*</span>姓名</h3>
						         <input type="input" value="<?=$coach->fullname?>" name="fullname" id="fullname" placeholder="姓名">
		 	          </div>


			          <div class="formgroup">
			               <h3><span class="mustspan">*</span>性别</h3>
			               <div class="inputcontent">
			                    <span svar='1' class="sexselector buttondiv">帅哥</span> 
			                    <span svar='2' class="sexselector buttondiv">美女</span> 
 			               </div>
		 	          </div>
			          <div class="formgroup">
			               <h3><span class="mustspan">*</span>身高</h3>
						   <input type="input" value="<?=$coach->height?>" name="height" id="height" placeholder="厘米">
		 	          </div>
			          <div class="formgroup">
			               <h3>体重</h3>
						        <input type="input" value="<?=$coach->weight?>" name="weight" id="weight" placeholder="公斤">
		 	          </div>
			          <div class="formgroup">
			               <h3>出生年月</h3>
						        <input type="input" value="<?=$coach->birthday?>" name="birthday" id="birthday" placeholder="格式:1990-01-01">
			          </div>

 			          <div class="formgroup">
			               <h3>qq号</h3>
						         <input type="input" value="<?=$coach->qqnumber?>" name="qqnumber" id="qqnumber" placeholder="qq号码">
		 	          </div>


               <div class="formgroup" style="height:101px;">
                         <h3>自我介绍</h3>
                   <textarea name="selfintro" id="selfintro" placeholder="一两句话介绍你自己"><?=$coach->description?></textarea>
                    <div class="clearbox"></div>
                </div>


               <div class="formgroup" style="height:101px;">
                      <h3>执教经历</h3>
                      <textarea name="resume" id="resume" placeholder="执教经历"><?=$coach->resume?></textarea>
                      <div class="clearbox"></div>
               </div>

                <div class="formgroup" style="height:101px;">
                    <h3>所获奖项</h3>
                   <textarea name="sporttitle" id="sporttitle" placeholder="曾获得过的奖项"><?=$coach->sporttitle?></textarea>
                    <div class="clearbox"></div>
                </div>



  		 	          <div class="blankbox"></div>

		        </div>
 
	</div>		    

	      <div style="width:90%;  text-align:center; margin:auto; margin-top:20px;">
				  <button id="submitButton" type="" class="btn btn-primary">
				     <div id="submitButtonText">设置</div>
				  </button>
	      </div>

	 	  <div style="height:20px;">
	       </div>

</div>
 
<script type="text/javascript">

   var sexvar = '<?=$coach->sex?>';
   var userid = '';
   var phonenumber = '';
   var wx_openid = '<?=$wx_openid?>';

   $(".sexselector").on('click',function(){
        var selectedvar = $(this).attr("svar");
        $(".sexselector").removeClass("buttondiv_selected");
        $(".sexselector").addClass("buttondiv");
        $(this).addClass("buttondiv_selected");
        $(this).removeClass("buttondiv");
        sexvar = selectedvar;
   });

   $(".stypeselector").on('click',function(){

    	   var selectstatus = $(this).attr("selectstatus");
   	    if(selectstatus=='selected'){
           $(this).attr("selectstatus","unselected");
           $(this).removeClass("buttondiv_selected");
           $(this).addClass("buttondiv");
   	    }else{

		   	   if($('#stypeselectdiv .buttondiv_selected').length > 2){
		   	   	   //alert("最多只允许选择3项");
                 layer.open({
				    content: '最多只允许选择3项',
				    className: 'bluelayer',
				    time: 2
				});

		   	   	   return;
		   	   }

           $(this).attr("selectstatus","selected");
           $(this).removeClass("buttondiv");
           $(this).addClass("buttondiv_selected");

   	    }
    	      
   });
 
   $("#userthumb").on('click',function(){
         $("#userthumbfile").click();
   });


  function upload (fileupload_id) {

	  	layer.open({
		    content: '正在上传',
		    className: 'bluelayer'
		});

   
       $("#uploadbg").attr("src","images/uploadbg2.png"); 
      
        $.ajaxFileUpload({
             url         :'/api_fileupload.php',
             secureuri   :false,
             fileElementId  : fileupload_id ,
             dataType    : 'json',
             success: function (data, status)            //相当于java中try语句块的用法
             {
                 $("#userthumb").attr("src",data.filepath);
                 layer.open({
          				    content: '上传成功',
          				    className: 'bluelayer',
          				    time: 1
          				});

             },
             error: function (data, status, e)            //相当于java中catch语句块的用法
             {
                layer.open({
				    content: '出错了!可能是网络有点慢,请尝试从手机相册中选择照片上传',
				    tbtn: ['OK']
				});
                //$("#uploadbg").attr("src","images/uploadbg.png"); 
              }

         });
          return true;
   }
 
    var currentstep = 1;
    $("#submitButton").on('click',function(){
    	if(currentstep==1){
	         //$("#step1").fadeOut(300);
 	         sendInfo_1();
      	}
    	if(currentstep==2){
 	         sendInfo_2();
     	}
    	if(currentstep==3){
             sendInfo_3();
     	}
 
    });

    function showlayer(showword){
			layer.open({
			    content:showword,
			    style: 'background-color:#09C1FF; color:#fff; border:none;',
			    time: 2
			});
    }

    function sendInfo_1(){

 	    //获取所选取的
 	    var stype_arr = new Array();
  
 	    var fullname = $("#fullname").val();
 	    var phonenumber = $("#phonenumber").val();
 	    var qqnumber = $("#qqnumber").val();
 	    var sex = sexvar;
 	    var height = $("#height").val();
 	    var weight = $("#weight").val();
 	    var birthday = $("#birthday").val();
 	    var thumb = $("#userthumb").attr("src");
      var selfintro = $("#selfintro").val();
      var resume = $("#resume").val();
      var sporttitle = $("#sporttitle").val();


 	    layer.open({
  		    content: '正在注册',
  		    className: 'bluelayer'
  		});

        $.ajax({
            url: '/index.php/coach/admin_baseinfo_handle',
            type: 'POST',
            data:{wx_openid:wx_openid, fullname:fullname,phonenumber:phonenumber,qqnumber:qqnumber,sex:sex,height:height,weight:weight,birthday:birthday,thumb:thumb,selfintro:selfintro,resume:resume,sporttitle:sporttitle},
            dataType: 'json',
            error: function(){
                  alert('Error loading PHP document'); 
                  posting = false;
                 },
            success: function(result){
 

				   if(result.result==7){
                layer.open({
						    content: '请重新登录',
						    className: 'bluelayer',
						    time: 2
					  });
                      return;
                 }


                if(result.result==1){
                      layer.open({
						    content: '修改完成',
						    className: 'bluelayer',
						    time: 2
						});
                      return;
		 	         //send sms

                }else{
                      layer.open({
						    content: '请填写完整',
						    className: 'bluelayer',
						    time: 2
						});
                      return;

                }
                posting = false;
            }
        });

    }

 
    // function sendInfo_3(){
    	
    //    var userthumb = $("#userthumb").attr("src");
    //    var selfintro = $("#selfintro").val();
    //    var sporttitle = $("#sporttitle").val();
    //    var resume = $("#resume").val();

    //     $.ajax({
    //         url: '/api_createinfo_3.php',
    //         type: 'POST',
    //         data:{ userid:userid,userthumb:userthumb,selfintro:selfintro,sporttitle:sporttitle,resume:resume},
    //         dataType: 'json',
    //         error: function(){
    //               alert('Error loading PHP document'); 
    //               posting = false;
    //              },
    //         success: function(result){


    //             if(result.result==1){
    //                   showlayer("已完成注册");
			 //         $("#step3").hide();
			 //         $("#step4").fadeIn(500);

    //                   $("#submitButton").hide();
    //                   currentstep ++;
		 	//          //send sms
    //                  $('html, body').animate({scrollTop:220}, 'slow'); 

    //             }else{
    //                  alert("请填写完整");
    //             }
    //             posting = false;
    //         }
    //     });
    // }

</script>



 

<?php 
	include_once("footer.php");
?>


